const got = require('got')
module.exports = class {
  constructor() {
    this.UA = 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1'
  }
  post(params) {
    if (!params?.headers) {
      params.headers = {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'User-Agent': this.UA
      }
    }
    return new Promise(async (reslove) => {
      try {

        const result = await got({
          ...params,
          method: 'post',
          timeout: {
            response: 50000
          }
        })
        reslove(result.body)
      } catch (error) {
        reslove(JSON.stringify({ status: 'error' }))

      }

    })
  }
  get(params) {
    try {
      if (!params?.headers) {
        params.headers = {
          'Content-Type': 'application/json',
          'User-Agent': this.UA
        }
      }
      return new Promise(async (reslove) => {
        const result = await got({
          ...params,
          method: 'get',
          timeout: {
            response: 50000
          }
        })
        reslove(result.body)
      })
    } catch (error) {
    }
  }

}